<template>
  <div class="a1">
    <h3>商家登录</h3>
    <el-form
      :model="ruleForm"
      status-icon
   
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="账号" prop="username" class="aa">
        <el-input type="username" v-model="ruleForm.username"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password" class="aa">
        <el-input type="password" v-model="ruleForm.pwd"></el-input>
      </el-form-item>
      <el-form-item label="手机号" prop="mobile" class="aa">
        <el-input v-model="ruleForm.mobile"></el-input
        ><button @click="SmsCode">发送验证码</button>
      </el-form-item>
      <el-form-item label="验证码" prop="sms_code" class="aa">
        <el-input v-model="ruleForm.sms_code"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm">登录</el-button><br />&emsp;&emsp;&emsp;&emsp;&emsp;
        <a href="/">点击登录顾客账号</a>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import Axios from "axios";
export default {
  name: "",
  data() {
    return {
      ruleForm: {
        username: "",
        pwd: "",
        mobile: "",
        sms_code: "",
      },
    };
  },
  props: {},

  components: {},

  created() {},

  mounted() {},

  methods: {
    Login() {
      this.$router.push("/login");
    },
    SmsCode() {
      Axios.post("http://127.0.0.1:8000/user/sms_code/", this.ruleForm).then(
        (res) => {
          console.log("发送验证码的响应>>>", res);
          if (res.data.code == 200) {
            this.$notify({
              title: "成功",
              message: "短信验证码发送成功",
              type: "success",
            });
          } else {
            this.$notify.error({
              title: "错误",
              message: res.data.msg,
            });
          }
        }
      );
    },
    submitForm(){
        Axios.post('http://127.0.0.1:8000/user/merchant_login/', this.ruleForm)
        .then(res=>{
            console.log("商家登录的响应:",res.data)
            if (res.data.code == 200){
                this.$notify({
                title: '成功',
                message: '登录成功',
                type: 'success',
            })
            localStorage.setItem("token",res.data.token)
            this.$router.push('/merchant_gl')	//登录验证成功路由实现跳转
            }else{
                this.$notify.error({
                title: '错误',
                message: res.data.msg
        });
            }   
        }).catch(err=>{
            console.log(err)
        })
      },
  },

  computed: {},

  watch: {},

  directives: {},

  filters: {},
};
</script>

<style>
.aa {
  width: 400px;
}
.a1 {
  width: 500px;
  height: 500px;
}
</style>